/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Dao.AlunoDao;
import Dao.AlunoDaoImplJPA;
import Dao.HistoricoTurmaDao;
import Dao.HistoricoTurmaDaoImplJPA;
import Dao.TurmaDao;
import Dao.TurmaDaoImplJPA;
import Pojo.Aluno;
import Pojo.Historico;
import Pojo.HistoricoTurma;
import Pojo.Turma;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author thiago
 */
public class HistoricoTurmaDaoImplJPATeste {
    
    public HistoricoTurmaDaoImplJPATeste() {
    }
    
    @BeforeClass
    public static void setUpClass() {
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}
    
     @Test
    public void inserirDaCerto(){
       HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        HistoricoTurma historicoTurma = new HistoricoTurma(3,16,70,true);
        assertTrue(historicoTurmaDao.inserir(historicoTurma));
    }
           
    @Test
    public void alterarDaCerto(){
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        HistoricoTurma historicoTurma = new HistoricoTurma(3,18,50,false);
        assertTrue(historicoTurmaDao.alterar(historicoTurma));
    }
    
    @Test
    public void alterarDaErrado(){
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        HistoricoTurma historicoTurma = new HistoricoTurma(5,16,40,true);
        assertFalse(historicoTurmaDao.alterar(historicoTurma));
    }
    
    @Test
    public void removerDaCerto(){
       HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        HistoricoTurma historicoTurma = new HistoricoTurma(3,16,70,true);
        assertTrue(historicoTurmaDao.remover(historicoTurma));
    }
    
    @Test
    public void removerDaErrado(){
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        HistoricoTurma historicoTurma = new HistoricoTurma(8,10,45,true);
        assertFalse(historicoTurmaDao.remover(historicoTurma));
    }
    
    @Test
    public void verificarAlunoCadastradoTurmaDaCerto(){
            AlunoDao alunoDao = new AlunoDaoImplJPA();
            Aluno aluno = new Aluno(1,"Thiago","09989403643");
            alunoDao.inserir(aluno);
            
            TurmaDao turmaDao = new TurmaDaoImplJPA();
            Turma turma = new Turma(1,2012, 2, "ctan", "08:00", 72, false);
            turmaDao.inserir(turma);
            
            HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
            HistoricoTurma historicoTurma = new HistoricoTurma(10, 60, true, aluno,turma);
            historicoTurma.setId(1);
            historicoTurmaDao.inserir(historicoTurma);
            assertEquals(1, historicoTurmaDao.verificarAlunoCadastradoTurma(aluno, turma));
    }
    
    @Test
    public void verificarAlunoCadastradoTurmaDaErrado(){
        Aluno aluno = new Aluno(10,"Thiago","09989403643");
        Turma turma = new Turma(20,2012, 2, "ctan", "08:00", 72, false);

        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        assertEquals(0, historicoTurmaDao.verificarAlunoCadastradoTurma(aluno, turma));
    }

    @Test
    public void pesquisarAlunosTurmaDaCerto(){
        Turma turma = new Turma(1,2012, 2, "ctan", "08:00", 72, false);
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();

        assertNotSame(0, historicoTurmaDao.pesquisarAlunosTurma(turma).size());
    }
    
    @Test
    public void pesquisarAlunosTurmaDaErrado(){
        Turma turma = new Turma(20,2012, 2, "ctan", "08:00", 72, false);
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();

        assertSame(0, historicoTurmaDao.pesquisarAlunosTurma(turma).size());
    }
    
    @Test
    public void pesquisarPorAlunoETurmaDaCerto(){
        Aluno aluno = new Aluno(1,"Thiago","09989403643");
        Turma turma = new Turma(1,2012, 2, "ctan", "08:00", 72, false);
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        
        assertNotNull(historicoTurmaDao.pesquisarPorAlunoETurma(aluno, turma));
    }
    
    @Test
    public void pesquisarPorAlunoETurmaDaErrado(){
        Aluno aluno = new Aluno(1,"Thiago","09989403643");
        Turma turma = new Turma(20,2012, 2, "ctan", "08:00", 72, false);
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        
        assertNull(historicoTurmaDao.pesquisarPorAlunoETurma(aluno, turma));
    }
    
    @Test
    public void pesquisarPorTurmaDaCerto(){
        Turma turma = new Turma(1,2012, 2, "ctan", "08:00", 72, false);
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        
        assertNotSame(0,historicoTurmaDao.pesquisarPorTurma(turma).size());
    }
    
    @Test
    public void pesquisarPorTurmaDaErrado(){
        Turma turma = new Turma(20,2012, 2, "ctan", "08:00", 72, false);
        HistoricoTurmaDao historicoTurmaDao = new HistoricoTurmaDaoImplJPA();
        
        assertSame(0,historicoTurmaDao.pesquisarPorTurma(turma).size());
    }
    
}